package com.burgeon.backend.SHOPBACKEND.controller;


import com.burgeon.backend.SHOPBACKEND.entity.Classify;
import com.burgeon.backend.SHOPBACKEND.entity.ClassifyItem;
import com.burgeon.backend.SHOPBACKEND.service.GoodsClassifyItemService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("shopbackent/classifyitem")
public class GoodsClassifyItemController extends BaseController{

    @Autowired
    private GoodsClassifyItemService goodsClassifyItemService;

    @RequestMapping("show")
    public ResponseResult<List<Classify>> getClassifyItem(String account) {
        List<Classify> data =  goodsClassifyItemService.showClassifyIstem(account);
        return new ResponseResult<List<Classify>>(SUCCESS, data);
    }

    /**
     * 添加商品分类明细类型
     *
     * @param classifyItem
     * @return
     */
    @RequestMapping("insert")
    public ResponseResult<Void> insertClassify(ClassifyItem classifyItem,String account) {
        classifyItem.setToken(account);
        classifyItem.setAccount(account);
        goodsClassifyItemService.insertClassifyItem(classifyItem);
        return new ResponseResult<Void>(SUCCESS);
    }

    /**
     * 根据ID删除商品类型
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public ResponseResult<Void> deleteClassify(Integer id) {
        goodsClassifyItemService.deleteClassifyItem(id);
        return new ResponseResult<Void>(SUCCESS);
    }

    /**
     * 根据ID修改商品类型
     * @param classifyItem
     * @return
     */
    @RequestMapping("update")
    public ResponseResult<Void> updateClassifyById(ClassifyItem classifyItem) {
        goodsClassifyItemService.upClassifyItemById(classifyItem);
        return new ResponseResult<Void>(SUCCESS);
    }

}
